package com.young.config;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

import com.young.entity.Address;
import com.young.entity.Person;
import com.young.repository.AddressRepository;
import com.young.repository.PersonRepository;

@Component
public class MyAppListener implements ApplicationListener<ApplicationReadyEvent>{

	@Autowired
	private AddressRepository addressRepository;
	
	@Autowired
	private PersonRepository personRepository;
	
	
	@Override
	public void onApplicationEvent(ApplicationReadyEvent event) {
		List<Address> addrList = new ArrayList();
		addrList.add(new Address("河南省"));
		addrList.add(new Address("河北省"));
		addrList.add(new Address("湖南省"));
		addrList.add(new Address("湖北省"));
		addrList.add(new Address("山东省"));
		addrList.add(new Address("陕西省"));
		addrList.add(new Address("广东省"));
		addrList.add(new Address("广西省"));
		addressRepository.save(addrList);
		
		personRepository.save(new Person("李白",24,addrList.get(0),
				"https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1373411777,3992091759&fm=27&gp=0.jpg",new Date()));
		personRepository.save(new Person("李黑",25,addrList.get(1),
				"https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1373411777,3992091759&fm=27&gp=0.jpg",new Date()));
		personRepository.save(new Person("李红",26,addrList.get(2),
				"https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1373411777,3992091759&fm=27&gp=0.jpg",new Date()));
		personRepository.save(new Person("李蓝",27,addrList.get(3),
				"https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1373411777,3992091759&fm=27&gp=0.jpg",new Date()));
	}

}
